
************************************************************************************************************************************************
****************************** REPLICATION CODE: RELIGION AND BRAZILIAN POLITICS 
****************************** 2019. Cambridge University Press
****************************** By Amy Erica Smith (amyericas@gmail.com) 

****************************** ANALYSIS OF 2012 FACEBOOK STUDY



****************************************** VARIABLE CODING **************************************************************************************

use "C:\Users\aesmith2\Dropbox\Work\Data\Brazil_facebook study 2012\Data\religion local election study.dta", clear
********************************************** CLEAN UP DATA
recode campaigninterest knowscandidate decided cand1_voteprob cand1_competent cand1_intelligent cand1_honest cand2_voteprob cand2_competent ///
	cand2_intelligent cand2_honest cand3_voteprob cand3_electedprob cand4_voteprob cand4_electedprob cand5_voteprob cand5_electedprob ///
	cand6_voteprob cand6_electedprob screener1a screener1b candphoto_race candphoto_race2 candphoto_class religionid pentecostalcharismatic ///
	bornagain religionattendancefreq screener2 partyid firstroundvote partyaffiliation childmarriageblack ownrace1 ownrace2 sex age income ///
	ipadraffle (-99 = .)


******************************************* EXPERIMENTAL TREATMENT AND OUTCOMES 
g treatment = 1 if cand3_voteprob != .
	replace treatment = 2 if cand4_voteprob != .
	replace treatment = 3 if cand5_voteprob != .
	replace treatment = 4 if cand6_voteprob != .
	lab def treatment 1 "Control" 2 "Gay Rights Activism" 3 "Clergy Rejection" 4 "Activism & Clergy Rejection", modify
	lab val treatment treatment
	lab var treatment "Clergy Influence Treatment Condition"
egen gayexp_voteprob = rowmean(cand3_voteprob cand4_voteprob cand5_voteprob cand6_voteprob)
	replace gayexp_voteprob = (gayexp_voteprob-1)/6
egen gayexp_electedprob = rowmean(cand3_electedprob cand4_electedprob cand5_electedprob cand6_electedprob)
	replace gayexp_electedprob = (gayexp_electedprob-1)/6

***** FICTIONAL CANDIDATE'S PARTY
sencode party3, replace
	lab var party3 "Fictional Candidate Party"

******************************************* INDEPENDENT VARIABLES 
***** RELIGIOUS AFFILIATION AND BEHAVIOR
recode religionid (1=1) (2=2) (3 4 = 3) (5=4), g(religion)
	lab def religion 1 "Catholic" 2 "Evangelical/Protestant" 3 "None" 4 "Atheist" 5 "Other", modify
	lab val religion religion
lab def pentecostalcharismatic 1 "Pentecostal" 2 "Charismatic" 3 "Neither"
	lab val pentecostalcharismatic pentecostalcharismatic
	recode pentecostalcharismatic (1 2 = 1) (3 = 0), g(pentchar)
recode bornagain (2 = 0)
recode religion (1=1) (2/5=0), g(catholic)
recode religion (2=1) (1 3/5=0), g(evangelical)
recode religion (3 4=1) (1/2 5=0), g(noreligion)
recode religion (5=1) (1/4=0), g(otherreligion)

g churchfreq = (5-religionattendancefreq)/4

***** RESPONDENT'S PARTY AFFILIATION
lab def partyaffiliation 1 "DEM" 2 "PCB" 3 "PCdoB" 4 "PCO" 5 "PDT" 6 "PEN" 7 "PHS" 8 "PMDB" 9 "PMN" 10 "PP" 11 "PPL" 12 "PPS" 13 "PR" 14 "PRB" 15 "PRP" ///
	16 "PRTB" 17 "PSB" 18 "PSC" 19 "PSD" 20 "PSDB" 21 "PSDC" 22 "PSL" 23 "PSOL" 24 "PSTU" 25 "PT" 26 "PTB" 27 "PTC" 28 "PTdoB" 29 "PTN" 30 "PV"
lab val partyaffiliation partyaffiliation

***** INDICATOR FOR WHETHER RESPONDENT BELONGS TO SAME PARTY AS FICTIONAL CANDIDATE
g copartisan = ((partyaffiliation == 8 & party3 == 3) | (partyaffiliation == 20 & party3 == 1) | (partyaffiliation == 25 & party3 == 2))

***** SEX
g female = sex-1

***** POLITICAL INTEREST
*campaigninterest

***** RACE
recode ownrace1 (2/5 = 0), g(white)

***** AGE
g age2 = age + 17
recode age2 (0/25 = 1) (26/40 = 2) (41/80 = 3), g(edad)
	lab def edad 1 "0-25 years" 2 "26-40 years" 3 "41-80 years"
	lab val edad edad

***** INCOME
*income
recode income (1/3 = 0) (4/8 = 1), g(highincome)

***** PRESIDENTIAL VOTE
recode firstroundvote (2/8 = 0), g(presvote_dilma)
recode firstroundvote (1 3/8 = 0) (2 = 1), g(presvote_serra)
recode firstroundvote (1/5 7/8 = 0) (6 = 1), g(presvote_turnout)

***** PARTY ID
recode partyid (2 = 0), g(haspid)



************************************************************************************************************************************************
************************************************************************************************************************************************
****************************************** ANALYSIS ********************************************************************************************

****************************** FIGURE 7.3: Impact of Candidate Activism and Clergy Endorsements on Candidate Support, Facebook 2012
global vars catholic evangelical noreligion pentchar bornagain religionattendancefreq ///
	campaigninterest haspid presvote_dilma presvote_serra white age income
preserve
reg gayexp_voteprob i.treatment $vars
	margins i.treatment, post 
	parmest, norestore
sencode parm, replace
	rename parm treatment
graph twoway (bar estimate treatment if treatment == 1, lcolor(black) fcolor(gs0)) ///
			(bar estimate treatment if treatment == 2, lcolor(black) fcolor(gs5)) ///
			(bar estimate treatment if treatment == 3, lcolor(black) fcolor(gs10))  ///
			(bar estimate treatment if treatment == 4, lcolor(black) fcolor(gs15)) ///
			(rspike min95 max95 treatment, lcolor(black)), ///
	graphregion(fcolor(white) lcolor(white)) xtitle("") xlabel(none) ylabel(.3(.1).6) ///
	ytitle("Level of Candidate" "Support (0-1 Scale)", margin(small)) title("All Respondents", span color(black) size(medium)) ///
	legend(order(1 "Control" 2 "Gay Rights" "Activism" 3 "Evangelical" "Clergy Rejection" 4 "Activism &" "Clergy Rejection" ) span symxsize(6) size(small)) ///
	name(all, replace) fysize(70) fxsize(65)
restore
preserve
reg gayexp_voteprob i.treatment##i.religion
	margins i.treatment#i.religion, post 
	parmest, norestore
egen religion = seq(), f(1) t(4)
	lab def religion 1 "Catholics" 2 "Evangelicals/Pentecostals" 3 "No Religion" 4 "Other Religion", modify
	lab val religion religion
egen treatment = seq(), f(1) t(4) block(4)
	lab def treatment 1 "Control" 2 "Gay Rights Activism" 3 "Clergy Rejection" 4 "Activism & Clergy Rejection", modify
	lab val treatment treatment
graph twoway (bar estimate treatment if treatment == 1, lcolor(black) fcolor(gs0)) ///
			(bar estimate treatment if treatment == 2, lcolor(black) fcolor(gs5)) ///
			(bar estimate treatment if treatment == 3, lcolor(black) fcolor(gs10))  ///
			(bar estimate treatment if treatment == 4, lcolor(black) fcolor(gs15)) ///
			(rspike min95 max95 treatment, lcolor(black)), ///
	by(religion, col(2) graphregion(fcolor(white) lcolor(black)) note("") legend(off)  ) ///
	xtitle("") xlabel(none) ytitle("Level of Candidate Support (0-1 Scale)", margin(small)) ///
	name(byreligion, replace) 
restore
graph combine all byreligion, col(2) xsize(6.5) iscale(.9) ///
	graphregion(fcolor(white) lcolor(black)) ///
	note("Source: Religion, Race, and Class Online Experimental Study, 2012. Whiskers represent 95% confidence intervals.", span)  
****************************** END FIGURE 7.3: Impact of Candidate Activism and Clergy Endorsements on Candidate Support, Facebook 2012


******************************  CHAPTER 7, analysis not shown: Impact of Candidate Activism and Clergy Endorsements on Electability, Facebook 2012
do "C:\Users\aesmith2\Dropbox\Work\research in progress\book project\Analysis\Setup_Facebook2012.do"
preserve
reg gayexp_electedprob i.treatment
	margins i.treatment, post 
	parmest, norestore
sencode parm, replace
	rename parm treatment
graph twoway (bar estimate treatment if treatment == 1, lcolor(black) fcolor(gs0)) ///
			(bar estimate treatment if treatment == 2, lcolor(black) fcolor(gs5)) ///
			(bar estimate treatment if treatment == 3, lcolor(black) fcolor(gs10))  ///
			(bar estimate treatment if treatment == 4, lcolor(black) fcolor(gs15)) ///
			(rspike min95 max95 treatment, lcolor(black)), ///
	graphregion(fcolor(white) lcolor(white)) xtitle("") xlabel(none) ylabel(.3(.1).6) ///
	ytitle("Estimate of Candidate" "Electability (0-1 Scale)", margin(small)) title("All Respondents", span color(black) size(medium)) ///
	legend(order(1 "Control" 2 "Gay Rights" "Activism" 3 "Evangelical" "Clergy Rejection" 4 "Activism &" "Clergy Rejection" ) span symxsize(6) size(small)) ///
	name(all, replace) fysize(70) fxsize(65)
restore
preserve
reg gayexp_electedprob i.treatment##i.religion
	margins i.treatment#i.religion, post 
	parmest, norestore
egen religion = seq(), f(1) t(4)
	lab def religion 1 "Catholics" 2 "Protestants/Pentecostals" 3 "No Religion" 4 "Other Religion", modify
	lab val religion religion
egen treatment = seq(), f(1) t(4) block(4)
	lab def treatment 1 "Control" 2 "Gay Rights Activism" 3 "Clergy Rejection" 4 "Activism & Clergy Rejection", modify
	lab val treatment treatment
graph twoway (bar estimate treatment if treatment == 1, lcolor(black) fcolor(gs0)) ///
			(bar estimate treatment if treatment == 2, lcolor(black) fcolor(gs5)) ///
			(bar estimate treatment if treatment == 3, lcolor(black) fcolor(gs10))  ///
			(bar estimate treatment if treatment == 4, lcolor(black) fcolor(gs15)) ///
			(rspike min95 max95 treatment, lcolor(black)), ///
	by(religion, col(2) graphregion(fcolor(white) lcolor(black)) note("") legend(off)  ) ///
	xtitle("") xlabel(none) ytitle("Estimate of Candidate Electability (0-1 Scale)", margin(small)) ///
	name(byreligion, replace) 
restore
graph combine all byreligion, col(2) xsize(6.5) iscale(.9) ///
	graphregion(fcolor(white) lcolor(black)) ///
	note("Source: Facebook 2012 Study. Whiskers represent 95% confidence intervals.", span)  
****************************** END CHAPTER 7, analysis not shown: Impact of Candidate Activism and Clergy Endorsements on Electability, Facebook 2012

